import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AiAlarmApi } from '#/api/moxi/aialarm';
import Dayjs from 'dayjs';

import {
    getRangePickerDefaultProps,
} from '#/utils';

/** 新增/修改的表单 */

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
    return [
        {
            fieldName: 'streamCode',
            label: '抓拍摄像头ID',
            component: 'Input',
            componentProps: {
                placeholder: '请输入抓拍摄像头ID',
                allowClear: true,
            },
        },
        {
            fieldName: 'alarmTime',
            label: '违规时间',
            component: 'RangePicker',
            componentProps: {
                ...getRangePickerDefaultProps(),
                allowClear: true,
            },
        },
    ];
}

/** 列表的字段 */
export function useGridColumns<T = AiAlarmApi.AiAlarm>(
    onStatusChange?: (
        newStatus: number,
        row: T,
    ) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
    return [
        {
            field: 'id',
            title: '序号',
        },
        {
            field: 'typeName',
            title: '告警类型',
        },
        {
            field: 'alarmTime',
            title: '发生时间',
            formatter: ({ cellValue }) => {
                return cellValue ? Dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
            },
        },
        {
            field: 'code',
            title: '触发摄像头编号',
            formatter: ({ row }) => {
                return row ? row.camera?.code : '';
            },
        },
        {
            field: 'streamCode',
            title: '摄像头ID',
        },
        {
            field: 'installationLocation',
            title: '摄像头位置',
            formatter: ({ row }) => {
                return row ? row.camera?.installationLocation : '';
            },
        },
        {
            field: 'className',
            title: '目标名称',
        },
        {
            title: '操作',
            width: 180,
            fixed: 'right',
            slots: { default: 'actions' },
        },
    ];
}
